<template>
	<view class="details">
		<u-navbar :fixed='false'>
			<view slot='left'>
				<view class='left-arrow' @click="goBack">
					<image src="../../static/list/back.png" mode=""></image>
				</view>
			</view>
			<view slot='right'>
				<view class='right-content'>
					<image src='../../static/list/star.png' class='title-start'></image>
					<image src='../../static/list/search.png' class='title-start'></image>
					<image src='../../static/list/cart.png'></image>
				</view>
			</view>
		</u-navbar>
		<!-- 课程详情 -->
		<view class='content'>
			<view class='content-title'>
				<view class="title-image"
					:style="{backgroundImage:`url(${course.courseCover})`}">
					<image src='../../static/common/vipLogo.png'></image>
				</view>
				<view class='title-content'>
					<view>
						<view class='right-title'>{{course.courseName}}</view>
						<view class='right-tips' v-if="course.description">{{course.description}}</view>
						<view class='right-tips' v-else>暂无课程介绍</view>
					</view>
					<view class='right-member'>{{course.discountPrice}}</view>
				</view>
			</view>
			<view class='content-foot'>
				<view class='item' v-for='(item,index) in courseNav' :key='item.id' @click='tabCourse(item)'
					:class='item.id == current?"active":""'>
					{{ item.name }}
				</view>
			</view>
			<swiper @change="changeCur" :current="current">
				<swiper-item>
					<scroll-view scroll-y="true" >
						<catalogue></catalogue>
					</scroll-view>
				</swiper-item>
				<swiper-item>
					<scroll-view scroll-y="true" >
						<downNotes></downNotes>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
		<view class="details-footer">
			<view class="footer-cart">加入购物车</view>
			<view class="footer-buy">立即购买</view>
		</view>
	</view>
</template>

<script>
	import catalogue from '@/components/details/catalogue.vue'
	import downNotes from '@/components/details/downNotes.vue'
	import {getDetail} from '@/api/course.js'
	export default {
		data() {
			return {
				course:{
					courseName:'',//课程名称
					courseCover: '',//课程图片封面
					description:'',//课程简介
					discountPrice: 0,//优惠价
				},
				courseNav: [{
						id: 0,
						name: '目录'
					},
					{
						id: 1,
						name: '下载笔记代码'
					}
				],
				current: 0,
			}
		},
		components:{
			catalogue,
			downNotes
		},
		onLoad(e) {
			let that=this
			getDetail({
				courseId:e.id
			}).then(res=>{
				let data=res.data
				that.coursr={
					courseName:data.courseName,
					courseCover: data.courseCover,
					description:data.bizCourseDetail.description,
					discountPrice: data.discountPrice
				}
				console.log(res.data)
			})
		},
		methods: {
			tabCourse(item) {
				this.current = item.id;
			},
			changeCur(e){
				this.current=e.detail.current
			},
			// 返回上一页
			goBack(){
				uni.navigateBack({
					delta:1
				})
			}
		}
	}
</script>

<style scoped lang='scss'>
	.details {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 100vh;
		overflow: hidden;
	}

	/deep/ .u-navbar__content {
		border-bottom: 1px solid #f5f5f5;
	}

	.left-arrow {
		display: flex;
		align-items: center;
		justify-content: center;
		padding-left: 10rpx;

		image {
			width: 18rpx;
			height: 33rpx;
		}
	}

	.right-content {
		display: flex;
		align-items: center;
		justify-content: space-between;

		image {
			width: 35rpx;
			height: 35rpx;
			padding-right: 10rpx;
		}

		.title-start {
			margin-right: 20rpx;
		}
	}

	.content {
		display: flex;
		flex-direction: column;

		.content-title {
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
			padding: 0 30rpx;

			.title-image {
				position: relative;
				width: 300rpx;
				height: 186rpx;
				border-radius: 5px;
				background-position: 0 0;
				background-repeat: no-repeat;
				background-size: 100% 100%;

				image {
					position: absolute;
					right: 0;
					top: 0;
					width: 52rpx;
					height: 22rpx;
				}
			}
		}

		.title-content {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			flex: 1;
			padding-left: 16rpx;

			.right-title {
				font-size: 32rpx;
				font-weight: 400;
				color: #191919;
			}

			.right-tips {
				font-size: 24rpx;
				height: 30px;
				font-weight: 400;
				color: #c5c5c5;
				margin-top: 8rpx;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
			}

			.right-member {
				font-size: 24rpx;
				font-weight: 700;
				color: #ff0018;
			}
		}

		.content-foot {
			display: flex;
			justify-content: space-around;
			align-items: center;
			height: 60rpx;
			margin-top: 14rpx;
			padding-bottom: 10rpx;

			.item {
				font-size: 28rpx;
				color: #303133;
				position: relative;

				&.active::after {
					content: '';
					position: absolute;
					left: 0;
					bottom: -20rpx;
					background-color: #0445ff;
					width: 100%;
					height: 4px;
					border-radius: 2px;
				}
			}
		}
	}
	.details-footer{
		width: 100%;
		height: 170rpx;
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		justify-content: space-around;
		align-items: center;
		border-top: 1px solid #c5c5c5;
		text-align: center;
		font-size: 26rpx;
		color: #fff;
		.footer-cart{
			width: 260rpx;
			height: 81rpx;
			line-height: 81rpx;
			border-radius: 40rpx;
			background: linear-gradient(90deg,#feb729 0,#ff9528);
		}
		.footer-buy{
			width: 260rpx;
			height: 81rpx;
			line-height: 81rpx;
			border-radius: 40rpx;
			background: linear-gradient(90deg,#fe5b5c 0,#ec0d0e);
		}
	}
</style>